//
//  BaseViewController.swift
//  SwiftDemo
//
//  Created by 李国卿 on 2020/1/16.
//  Copyright © 2020 guoqing.li. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
    // MARK: 定义属性
    var contentView : UIView?
    
    // MARK: 懒加载属性 unowed self 解决循环引用
    fileprivate lazy var animaImgView : UIImageView = {[unowned self] in
        let imgView = UIImageView(image: UIImage(named: "img_loading_1"))
        imgView.center = self.view.center;
        imgView.animationImages = [UIImage(named:"img_loading_1")!,UIImage(named:"img_loading_2")!]
        imgView.animationDuration = 0.5
        imgView.animationRepeatCount = LONG_MAX
        imgView.autoresizingMask = [.flexibleTopMargin,.flexibleBottomMargin]
        imgView.isUserInteractionEnabled = false
        return imgView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        
    }
}

extension BaseViewController{
    @objc func setupUI() {
        
        contentView?.isHidden = true
        
        view.addSubview(animaImgView)
        
        animaImgView.startAnimating()
        
        view.backgroundColor = UIColor.white;
    }
    
    func loadDataFinished() {
        
        animaImgView.stopAnimating()
        
        animaImgView.isHidden = true
        
        contentView?.isHidden = false;
        
        
        
    }
}
